package cn.itcast.account.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

// @LocalTCC注解：开启TCC事务
@LocalTCC
public interface AccountTCCService {

    // TCC模式相关注解
    /**
     * @Description:
     * @TwoPhaseBusinessAction注解：标记该接口方法是两阶段事务，一阶段（try）进行资源预留，二阶段进行事务的提交或回滚
     *                            commitMethod属性： 二阶段事务提交的方法名
     *                            rollbackMethod属性：二阶段事务回滚的方法名
     * @BusinessActionContextParameter注解：设置参数到BusinessActionContext中，用于二阶段事务提交或回滚获取参数值
     * @param userId
     * @param money
     * @return void
     */
    @TwoPhaseBusinessAction(name = "deduct", commitMethod = "confirm", rollbackMethod = "cancel")
    void deduct(@BusinessActionContextParameter(paramName = "userId") String userId,
                @BusinessActionContextParameter(paramName = "money")int money);

    //void deduct(String userId, int money);

    boolean confirm(BusinessActionContext ctx);

    boolean cancel(BusinessActionContext ctx);
}
